package com.futures.questionbank.ui.home;

import android.os.Build;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.annotation.RequiresApi;

import com.futures.questionbank.R;
import com.futures.questionbank.base.BaseActivity;

import butterknife.BindView;

public class InfoActivity2 extends BaseActivity {
    @BindView(R.id.webview)
    WebView webview;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.info_activity2);
        setTitle("考试动态");
    }

    @Override
    protected void loadData() {
        WebSettings webSettings = webview.getSettings();
        //支持javascript
        webview.getSettings().setJavaScriptEnabled(true);
        // 设置可以支持缩放
          webview.getSettings().setSupportZoom(true);
        // 设置出现缩放工具
         webview.getSettings().setBuiltInZoomControls(true);
        //扩大比例的缩放
          webview.getSettings().setUseWideViewPort(true);

        webview.getSettings().setLoadsImagesAutomatically(true);
        webview.getSettings().setDefaultTextEncodingName("utf-8");
        webview.getSettings().setDomStorageEnabled(true);
        webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        //使用app打开网页
        webview.setWebViewClient(new MyWebViewClient());
        //设置网页组件功能
        webview.setWebChromeClient(new MyWebChromeClient());
        //自适应屏幕
          webview.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
           webview.getSettings().setLoadWithOverviewMode(true);
        //  webview.loadUrl("https://www.baidu.com");

        webview.loadUrl("https://newapi.xuesai.net/FaXian/html/ArticleDetail.html?oldarticle_id=29&article_id=5913&userid=0&iden=AE0070A980069E0B83396096D83A57B3_xxx&token=a0915599cdc87530c46205fc1bcc3625&GlobalAppType=55&type=NX541J");
        //  webview.loadUrl("https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx0315251705682622581d5c941849809900&package=2384630800");

        //如果不设置WebViewClient，请求会跳转系统浏览器
      /* webview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                //该方法在Build.VERSION_CODES.LOLLIPOP以前有效，从Build.VERSION_CODES.LOLLIPOP起，建议使用shouldOverrideUrlLoading(WebView, WebResourceRequest)} instead
                //返回false，意味着请求过程里，不管有多少次的跳转请求（即新的请求地址），均交给webView自己处理，这也是此方法的默认处理
                //返回true，说明你自己想根据url，做新的跳转，比如在判断url符合条件的情况下，我想让webView加载http://ask.csdn.net/questions/178242
                   view.loadUrl(url);
                return super.shouldOverrideUrlLoading(view, url);
            }
        });*/
    }


    class MyWebViewClient extends WebViewClient {
        @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            view.loadUrl(request.getUrl().toString());
            return true;
        }
    }

    class MyWebChromeClient extends WebChromeClient {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
        }
    }
}
